package com.lee.transactionaldemo.service.notsupport;

import com.lee.transactionaldemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author ：liylw
 * @date ：Created in 2021/4/23 14:26
 */
@Service
public class NotSupport1 {

    @Autowired
    private UserService userService;

    @Autowired
    private NotSupport2 notSupport2;


    /**
     * 正常运行
     */
    public void test1(){
        userService.saveUserASuccess();
        notSupport2.testSuccess();
    }


    /**
     * 正常运行
     */
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public void test2(){
        userService.saveUserASuccess();
        notSupport2.testSuccess();
    }


    /**
     *  A没插入，B插入成功。
     */
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public void test3(){
        userService.saveUserASuccess();
        notSupport2.testFail();
    }

    /**
     *  A没插入，B插入成功。
     */
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public void test4(){
        notSupport2.testSuccess();
        userService.saveUserAFail();
    }
}
